package com.java.comprehensive.arithmetic.leecode.tags.array;

/**
 * @Author: 窦绍飞
 * @Date: 2022/6/29
 */
public class LeetCode_35 {

	public static int searchInsert(int[] nums, int target) {

		if (nums.length < 1) return 0;

		int i = 0, j = nums.length - 1;
		while (i <= j) {
			int mid = i + (i + j) / 2;
			if (nums[mid] == target) {
				return mid;
			} else if (nums[mid] > target) {
				j = mid - 1;
			} else {
				i = mid + 1;
			}
		}
		return i;
	}

	public static void main(String[] args) {
		int[] nums = {1, 3, 5, 6};
		int num = 0;
		System.out.println(searchInsert(nums, num));
	}
}
